package cn.fintecher.gis.web;

import cn.fintecher.gis.annotation.CurrentOperator;
import cn.fintecher.gis.entity.GrantInfo;
import cn.fintecher.gis.model.request.BusinessFileRequest;
import cn.fintecher.gis.model.request.GrantRequest;
import cn.fintecher.gis.model.session.SessionModel;
import cn.fintecher.gis.service.GrantInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 批地相关接口
 * @Date: 18:00 2019/4/29
 */

@RestController
@RequestMapping("/api/grantInfoController")
@Api(value = "grantInfoController", description = "批地相关接口")
public class GrantInfoController extends BaseController {
    @Autowired
    private GrantInfoService grantInfoService;

    /**
     * 新增批地信息
     */
    @PostMapping("/addGrantInfo")
    @ApiOperation(value = "新增批地信息", notes = "新增批地信息")
    public ResponseEntity<Void> addGrantInfo(@RequestBody GrantRequest request,
                                             @ApiIgnore @CurrentOperator SessionModel operator) throws Exception {
        log.debug("REST request to addGrantInfo,{}", request);
        grantInfoService.addGrantInfo(request, operator);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/getGrantInfoByCode")
    @ApiOperation(value = "根据批地code查询对应的批地信息", notes = "根据批地code查询对应的批地信息")
    public ResponseEntity<List<GrantInfo>> getGrantInfoByCode(@RequestParam("code") String code) {
        List<GrantInfo> list = grantInfoService.getGrantInfoByCode(code);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("/getGrantInfoById/{id}")
    @ApiOperation(value = "根据批地id查询对应的批地信息", notes = "根据批地id查询对应的批地信息")
    public ResponseEntity<GrantInfo> getGrantInfoById(@PathVariable String id) {
        GrantInfo grantInfo = grantInfoService.getGrantInfoById(id);
        return ResponseEntity.ok().body(grantInfo);
    }

    @PostMapping("/editBusinessFile")
    @ApiOperation(value = "批地再次添加文件", notes = "批地再次添加文件")
    public ResponseEntity<Void> editBusinessFile(@RequestBody BusinessFileRequest request) {
        log.debug("REST request to editBusinessFile,{}", request);
        grantInfoService.editBusinessFile(request);
        return ResponseEntity.ok().build();
    }
}
